#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 3e5 + 10, INF = 0x3f3f3f3f;

ll n, L;
ll d[N];
map<ll, ll> hs;

void solve()
{
    cin >> n >> L;
    if (L % 3) { cout << 0 << '\n'; return; }
    hs[0]++;
    for (ll i = 1;i < n;i++) {
        cin >> d[i];
        d[i] = (d[i - 1] + d[i]) % L;
        hs[d[i]]++;
    }

    ll t = L / 3, ans = 0;
    for (auto [x, _] : hs) {
        if (_ == 0) continue;
        ll a = x, b = (x + t) % L, c = (x + 2 * t) % L;
        // cout << a << ' ' << b << ' ' << c << '\n';
        ans += hs[a] * hs[b] * hs[c];
        hs[a] = hs[b] = hs[c] = 0;
    }
    cout << ans;
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}